package com.java.multipledatasource.algorithm;

/**
 * @author hu
 * @version 1.0
 * @date 2021/1/19 0019 下午 12:18
 * @description
 */
public class NodeReverse {

    public static class Node{
        public int value;
        public Node next;
        public Node(int data){
            value =  data;
        }
    }

    public static class DoubleNode{
        public int value;
        public DoubleNode last;
        public DoubleNode next;
        public DoubleNode(int data) {
            value = data;
        }
    }

    public static Node reverseNodeList(Node head) {
        Node pre = null;
        Node next;

        while (head != null) {
           next = head.next;
           head.next = pre;
           pre  = head;
           head = next;
        }

        return pre;
    }

    public static DoubleNode reverseDoubleNodeList(DoubleNode head) {
        DoubleNode pre = null;
        DoubleNode next;
        while (head != null) {
            next = head.next;

            head.next = pre;
            head.last = next;
            pre = head;

            head = next;
        }


        return pre;
    }

    public static void main(String[] args) {
        Node node1 = new Node(1);
        Node node2 = new Node(2);
        Node node3 = new Node(3);
        node1.next = node2;
        node2.next = node3;
        reverseNodeList(node1);
    }
}
